import {config} from "./config"
import {Getuser} from "../api"
export const getcode = ()=>{
    let url = `https://gitee.com/oauth/authorize?client_id=${config.client_id}&redirect_uri=${config.redirect_uri}&response_type=code`;
    window.location.href = url;
}
export const analysis = (key)=>{
    let val;
    let params = window.location.search.slice(1);
    params.split("&").forEach(item=>{
        if(item.split("=")[0]===key){
            val = item.split("=")[1]
        }
    })
    return val;
}

export const getUser = async (cellback)=>{
    let code = analysis("code");
    if(code){
        let res = await Getuser({code})
        if(res.data.code===0){
            cellback(res.data.data,res.data.token)
        }
    }
}